import { Component, Vue, Inject } from 'vue-property-decorator';

import { IRoomUserBrokerChantMessage } from '@/shared/model/room-user-broker-chant-message.model';
import RoomUserBrokerChantMessageService from './room-user-broker-chant-message.service';
import AlertService from '@/shared/alert/alert.service';

@Component
export default class RoomUserBrokerChantMessageDetails extends Vue {
  @Inject('roomUserBrokerChantMessageService') private roomUserBrokerChantMessageService: () => RoomUserBrokerChantMessageService;
  @Inject('alertService') private alertService: () => AlertService;

  public roomUserBrokerChantMessage: IRoomUserBrokerChantMessage = {};

  beforeRouteEnter(to, from, next) {
    next(vm => {
      if (to.params.roomUserBrokerChantMessageId) {
        vm.retrieveRoomUserBrokerChantMessage(to.params.roomUserBrokerChantMessageId);
      }
    });
  }

  public retrieveRoomUserBrokerChantMessage(roomUserBrokerChantMessageId) {
    this.roomUserBrokerChantMessageService()
      .find(roomUserBrokerChantMessageId)
      .then(res => {
        this.roomUserBrokerChantMessage = res;
      })
      .catch(error => {
        this.alertService().showHttpError(this, error.response);
      });
  }

  public previousState() {
    this.$router.go(-1);
  }
}
